/**
 * 
 */
package cwinsor.com.leaf_raking;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author cwinsor
 *
 */
public class Main001 {



	/**
	 * @param args
	 */
	public static void main(String[] args) {

		RakerServices rakerServices;
		SupervisorServices supervisorServices;
		CustomerServices customerServices;

		Boolean printVersion = false;

		try {

			// prepare to write a .csv file
			String content;

			// read the raker list
			System.out.println("main: ----- new rakerList");
			rakerServices = new RakerServices();
			rakerServices.readCsvFile();
			//rakerServices.print();

			// read the supervisor list
			System.out.println("main: ----- new rakerList");
			supervisorServices = new SupervisorServices();
			supervisorServices.readCsvFile();
			//rakerServices.print();

			// read the customer list
			System.out.println("main: ----- new customerList");
			customerServices = new CustomerServices();
			customerServices.readCsvFile();
			//			customerServices.readXmlFile();
			//rakerServices.print();




			// read and check the supervisor list
			// read and check the customer list

			// name the file
			File outfile = new File("C:/Users/cwinsor/Documents/me/_BHRA_2013/leaf raking/schedule_files/raking_schedule_2013.csv");
			// if file doesnt exists, then create it
			if (!outfile.exists()) { outfile.createNewFile(); }
			// create writer,buffer				
			FileWriter fw = new FileWriter(outfile.getAbsoluteFile());
			BufferedWriter bw = new BufferedWriter(fw);

			// print a header - date and time
			DateFormat dateFormat = new SimpleDateFormat("MM/dd HH:mm");
			//get current date time with Date()
			Date date = new Date();
			//	System.out.println(dateFormat.format(date));
			bw.write("BHRA Raking Fundraiser - Schedule for November 9 10\n"
					+ "Schedule Ref F  "
					+ "\n\n");

			bw.write("SUPERVISORS:\n");
			bw.write("Make a note about payment amount and type on (this) hardcopy spreadsheet!!!!\n");
			bw.write("MORNING SUPERVISORS: get your equipment at -> BLANCHARD SCHOOL IN BOXBOROUGH CENTER (493 Massachusetts Ave Boxborough) 8AM <- \n");
			bw.write("AFTERNOON SUPERVISORS: get your equipment from the AM team at their last customer\n");
			bw.write("AFTERNOON SUPERVISORS: RETURN EQUIPMENT to BLANCHARD SCHOOL IN BOXBOROUGH CENTER when you are done !!!\n");
			bw.write("\n");
			bw.write("IN CASE OF A NO-SHOW: CALL THE RAKER CELL/HOME - IT IS ON SCHEDULE BELOW\n");
			bw.write("\n");
			bw.write("EQUIPMENT/SCHEDULE PROBLEMS:\n");
			bw.write("   Saturday -> Chris Winsor 978-621-2724\n");
			bw.write("   Sunday   -> Tom Dunn 978-844-2764\n");
			bw.write("\n");
			bw.write("PARENTS:\n");
			bw.write("Bring you rower to the first customer site where you will meet your supervisor and team.  Plan to arrive 15 minutes before the scheduled time\n");
			bw.write("Pick up your rower at the third customer site at the scheduled end time");
			bw.write("The supervisor will transport the rowers between customer sites");
			bw.write("\n");
			bw.write("\n");

			// for each day
			for (RakerColumns rakerColumns : RakerColumns.DAYS) {
				//		System.out.println("main: ----- " + day.name());

				// for each team number
				for (Team team : Team.TEAMS_NO_U) {
					//			System.out.println("main: ------- " + team.name());

					// for am/pm shift
					for (Shift shift : Shift.SHIFTS) {
						//				System.out.println("main: --------- " + shift.name());

						// write to the file
						bw.write(rakerColumns.name()
								+ "  " + shift.name()
								+ "  " + team.name()
								+ "\n");

						// identify the subset of supervisors (hopefully==1) for the day/shift/team in question
						SupervisorServices supervisorsThisShift = supervisorServices.getSupervisorsDayShiftTeam(rakerColumns,shift,team);

						// write to the file
						bw.write(supervisorsThisShift.toCsvString(""));

						// write to the file
						RakerServices rakersThisShift = rakerServices.getRakersDayShiftTeam(rakerColumns,shift,team);
						bw.write(rakersThisShift.toCsvString(""));

						// print to screen the subset of rakers for the day/shift/team in question
						//	System.out.println("main: -----------> totalRakerPower = "
						//			+ rakersThisShift.totalRakerPower());

						CustomerServices customersThisShift = customerServices.getCustomersDayShiftTeam(rakerColumns, shift, team);
						bw.write(customersThisShift.toCsvString());


						//	if (shift.equals(Shift.AM)) {
						//		bw.write("8:30,customer_1\n");
						//		bw.write("10:00,customer_2\n");
						//		bw.write("11:30,customer_3\n");
						//	}
						//	if (shift.equals(Shift.PM)) {
						//		bw.write("1:00,customer_1\n");
						//		bw.write("2:30,customer_2\n");
						//		bw.write("4:00,customer_3\n");
						//	}
						bw.write("\n");

					}
				}
			}
			System.out.println("main: ----- closing this file");
			bw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}






		//	supervisorList = new SupervisorList();
		//	supervisorList.readCsvFile();

		//	customerList = new CustomerList();
		//	customerList.readCsvFile();


		// get the members of the team
		//	teamX = new RakerList();
		// teamX = rakerList.getRakers("Sat2Am", 1);



		System.out.println("main: ----- done");

		//		System.out.println("main: ----- new the machine");
		//		RakingAssignmentMachine rakingAssignmentMachine = new RakingAssignmentMachine();
		//		System.out.println("main: ----- run the machine");
		//		rakingAssignmentMachine.run();
		//		System.out.println("main: ----- machine is done");

	}

}
